#include "PaFile.h"
#include "../XXqtDefine.h"
#include "./XXlogger.h"

PaFile::PaFile(const QString &path)
    :_paVarRef(_paVar),_path(path){
    auto var = XXqtDefine::variantFromJsonFile(path);
    _paVar = var;
    reload();
}

PaVarRef PaFile::operator[](const QVariant &key){
    return _paVarRef[key];
}
PaVarRef PaFile::ref(){
    return _paVarRef;
}
void PaFile::save(){
    if(!XXqtDefine::variantToJsonFile(_paVar.get(),_path,true)){
        xxLogStr(QString("[Warning] failure to save. path:%1").arg(_path));
    }
}
void PaFile::reload(){
    _paVar = XXqtDefine::variantFromJsonFile(_path);
}
